<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable name="time">
    <xsl:value-of  select="document('http://xobjex.com/cgi-bin/date.pl')/date/utc/@stamp"/>
</xsl:variable>
<xsl:variable name="context-owner">
   <xsl:value-of select="//metadata/owner"/>
</xsl:variable> 
        
<xsl:template match="/">
        <data>
            <xsl:apply-templates select="//metadata[contains(@place_id,'pl_context')]"/>
            <!-- current assumption: only one context place exists -->
        </data>
</xsl:template>

<xsl:template match="metadata">
    <metadata>
          <xsl:attribute name="target_place">
            <xsl:value-of select="@target_place"/>
          </xsl:attribute>
          <xsl:attribute name="name">
            <xsl:value-of select="@name"/>
          </xsl:attribute>
          <xsl:attribute name="place_id">
            <xsl:value-of select="@placeid"/>
          </xsl:attribute>
        <xsl:apply-templates/>
    </metadata>
</xsl:template>

<xsl:template match="metadata/status">
    <status>running</status>
</xsl:template>

<xsl:template match="metadata/actions">
    <actions>
        <action>
            <name>resume</name>
            <time><xsl:copy-of select="$time" /></time>
            <user><xsl:value-of select="$context-owner" /></user>
        </action> 
        <xsl:copy-of select="*"/>
    </actions>
</xsl:template>

<xsl:template match="metadata/*">
     <xsl:copy-of select="."/>  
</xsl:template>

</xsl:stylesheet>